#include <bits/stdc++.h>
#define int long long
#define PII pair <int, int>
using namespace std;
const int N = 5e3 + 5;
int n, pos, pos_, len;
vector <int> p[N];
void dfs1(int u, int dep) {
	if(dep > len) {
		len = len;
		pos = u;
	}
	for(int i : p[u]) dfs1(i);
}
signed main() {
//	freopen("forest.in", "r", stdin);
//	freopen("forest.out", "w", stdout);
//	ios :: sync_with_stdio(0);
//	cin.tie(0), cout.tie(0);
	cin >> n >> n;
	for(int i = 2, x; i <= n; i ++ ) {
		cin >> x;
		p[x].push_back(i);
		dfs1(1);
		pos_ = pos;
		dfs1(pos);
		
	}
	return 0;
}

